package org.springframework.core.io;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

/**
 * @Name UrlResource
 * @Description: 对 java.net.URL 进行资源定位的 [实现] 类。
 * @Version v1.0.0
 * @Author: lichao
 * @Date: 2024-03-15 15:16:07
 **/
public class UrlResource implements Resource {
    private final URL url;

    public UrlResource(URL url) {
        this.url = url;
    }

    @Override
    public InputStream getInputStream() throws IOException {
        URLConnection con = this.url.openConnection();
        try {
            return con.getInputStream();
        } catch (IOException e) {
            throw e;
        }
    }
}

